package com.dragon.mmochat.service;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.transaction.annotation.Transactional;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.MmochatMain;
import com.dragon.mmochat.dao.MmochatActivityRecordDao;
import com.dragon.mmochat.dao.MmochatBigMoneyDealDao;
import com.dragon.mmochat.dao.MmochatDealLogDao;
import com.dragon.mmochat.dao.MmochatDirectPayDao;
import com.dragon.mmochat.dao.MmochatEventDao;
import com.dragon.mmochat.dao.MmochatGangDao;
import com.dragon.mmochat.dao.MmochatGmDao;
import com.dragon.mmochat.dao.MmochatGmOptionLogDao;
import com.dragon.mmochat.dao.MmochatKbPayDao;
import com.dragon.mmochat.dao.MmochatKefuDao;
import com.dragon.mmochat.dao.MmochatPkTeamDao;
import com.dragon.mmochat.dao.MmochatRoleDao;
import com.dragon.mmochat.dao.MmochatSerialDao;
import com.dragon.mmochat.dao.MmochatShopDao;
import com.dragon.mmochat.dao.MmochatStatisticsDao;
import com.dragon.mmochat.dao.MmochatSerialDao.SerialClub;
import com.dragon.mmochat.model.MmochatActivityRecord;
import com.dragon.mmochat.model.MmochatEventLog;
import com.dragon.mmochat.model.MmochatRolePayInfo;
import com.dragon.mmochat.model.deal.MmochatBigMoneyDeal;
import com.dragon.mmochat.model.deal.MmochatDealLog;
import com.dragon.mmochat.model.enumType.MmochatBigMoneyDealType;
import com.dragon.mmochat.model.enumType.MmochatSecondRoleType;
import com.dragon.mmochat.model.gang.MmochatGang;
import com.dragon.mmochat.model.kefu.MmochatKefuOptionLog;
import com.dragon.mmochat.model.mergeServer.MergeStep1Model1;
import com.dragon.mmochat.model.mergeServer.MergeStep1Model4;
import com.dragon.mmochat.model.mergeServer.MergeStep2Model1;
import com.dragon.mmochat.model.pkteam.MmochatPkTeam;
import com.dragon.mmochat.model.role.MmochatGm;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.dragon.mmochat.model.role.MmochatRankPlayer;
import com.dragon.mmochat.model.role.MmochatSimplePlayer;
import com.dragon.mmochat.model.shop.MmochatPlayerShop;
import com.dragon.mmochat.model.statistics.MmochatBigMoneyStatistics;
import com.dragon.mmochat.model.statistics.MmochatDailyMoneyStatistics;
import com.dragon.mmochat.model.statistics.MmochatDailyUserStatistics;
import com.dragon.mmochat.model.statistics.MmochatMonthlyStatistics;
import com.dragon.mmochat.model.statistics.MmochatRoleLevelInfo;
import com.dragon.mmochat.model.statistics.MmochatRoleLevelInfoStatistics;
import com.dragon.mmochat.model.statistics.MmochatSmallMoneyStatistics;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class MmochatDaoService {
	private MmochatRoleDao roleDao = null;
	private MmochatSerialDao serialDao = null;
	private MmochatGangDao gangDao = null;
	private MmochatPkTeamDao pkTeamDao = null;
	private MmochatGmDao gmDao = null;
	private MmochatKefuDao kefuDao = null;
	private MmochatGmOptionLogDao kefuOptionLogDao = null;
	private MmochatDirectPayDao mmochatDirectPayDao = null;
	private MmochatKbPayDao mmochatKbPayDao = null;
	private MmochatStatisticsDao mmochatStatisticsDao = null;
	private MmochatDealLogDao mmochatDealLogDao = null;
	private MmochatBigMoneyDealDao mmochatBigMoneyDealDao = null;
	private MmochatActivityRecordDao mmochatActivityRecordDao = null;
	private MmochatShopDao mmochatShopDao = null;
	private MmochatEventDao mmochatEventDao = null;

	public void init() {
		initSerial();
	}

	public void setRoleDao(MmochatRoleDao roleDao) {
		this.roleDao = roleDao;
	}

	public void setSerialDao(MmochatSerialDao serialDao) {
		this.serialDao = serialDao;
	}

	public void setGangDao(MmochatGangDao gangDao) {
		this.gangDao = gangDao;
	}

	public void setPkTeamDao(MmochatPkTeamDao pkTeamDao) {
		this.pkTeamDao = pkTeamDao;
	}

	public void setGmDao(MmochatGmDao gmDao) {
		this.gmDao = gmDao;
	}

	public void setKefuDao(MmochatKefuDao kefuDao) {
		this.kefuDao = kefuDao;
	}

	public void setKefuOptionLogDao(MmochatGmOptionLogDao kefuOptionLogDao) {
		this.kefuOptionLogDao = kefuOptionLogDao;
	}

	public void setMmochatDirectPayDao(MmochatDirectPayDao mmochatDirectPayDao) {
		this.mmochatDirectPayDao = mmochatDirectPayDao;
	}

	public void setMmochatKbPayDao(MmochatKbPayDao mmochatKbPayDao) {
		this.mmochatKbPayDao = mmochatKbPayDao;
	}

	public void setMmochatStatisticsDao(
			MmochatStatisticsDao mmochatStatisticsDao) {
		this.mmochatStatisticsDao = mmochatStatisticsDao;
	}

	public void setMmochatDealLogDao(MmochatDealLogDao mmochatDealLogDao) {
		this.mmochatDealLogDao = mmochatDealLogDao;
	}

	public void setMmochatBigMoneyDealDao(
			MmochatBigMoneyDealDao mmochatBigMoneyDealDao) {
		this.mmochatBigMoneyDealDao = mmochatBigMoneyDealDao;
	}

	public void setMmochatActivityRecordDao(
			MmochatActivityRecordDao mmochatActivityRecordDao) {
		this.mmochatActivityRecordDao = mmochatActivityRecordDao;
	}

	public void setMmochatShopDao(MmochatShopDao mmochatShopDao) {
		this.mmochatShopDao = mmochatShopDao;
	}

	public void setMmochatEventDao(MmochatEventDao mmochatEventDao) {
		this.mmochatEventDao = mmochatEventDao;
	}

	// 获取skyId的角色列表
	public List<MmochatSimplePlayer> getRoleList(long skyId) {
		return roleDao.getRoleList(skyId);
	}

	// 获取skyId的所有角色列表
	public List<MmochatSimplePlayer> getAllRoleList(long skyId) {
		return roleDao.getAllRoleList(skyId);
	}

	// 创建新角色ID
	public int createNewRoleId() {
		return roleDao.createNewRoleId();
	}

	// 增加新的角色
	@Transactional
	public void createRole(long skyId, String name, int sexual, int family,
			int roleTypeValue, int friendListBmp, String suggest_name,
			String imei) {
		roleDao.createRole(skyId, name, sexual, family, roleTypeValue,
				friendListBmp, suggest_name, imei);
	}

	// 增加新的角色
	@Transactional
	public void createRole2(int roleId, long skyId, String name, int sexual,
			int family, int roleTypeValue, int friendListBmp,
			String suggest_name, String imei, long createTime, int smallMoney,
			int bigMoney, int level) {
		roleDao.createRole2(roleId, skyId, name, sexual, family, roleTypeValue,
				friendListBmp, suggest_name, imei, createTime, smallMoney,
				bigMoney, level);
	}

	// 删除角色
	@Transactional
	public void delRole(int id, boolean delete) {
		roleDao.delRole(id, delete);
	}

	// 获取roleId的角色
	public MmochatPlayer getRole(int roleId) {
		return roleDao.getRole(roleId);
	}

	// 获取roleId的角色
	public MmochatPlayer getRoleIncludeDeleted(int roleId) {
		return roleDao.getRoleIncludeDeleted(roleId);
	}

	// 更新角色第一次登陆游戏
	@Transactional
	public void updateRoleFirstEnterGame(String myPackage, String myStorage,
			String tasks, int login_time, int roleId) {
		roleDao.updateRoleFirstEnterGame(myPackage, myStorage, tasks,
				login_time, roleId);
	}

	// 批量更新角色离开游戏
	@Transactional
	public void batchUpdateRoleLeaveGame(List<Object[]> args) {
		roleDao.batchUpdateRoleLeaveGame(args);
	}

	// 更新任务列表
	@Transactional
	public void updateRoleTasks(String gsonTasks, int roleId) {
		roleDao.updateRoleTasks(gsonTasks, roleId);
	}

	// 批量更新角色交易完成后的数据
	@Transactional
	public void makeDeal(MmochatPlayer me, int myAddSmallMoney, String myImei,
			String myDealPackage, MmochatPlayer he, int hisAddSmallMoney,
			String hisImei, String hisDealPackage, List<Object[]> args) {
		roleDao.batchUpdateRoleAfterDeal(args);
		mmochatDealLogDao.addNewDealLog(me.getRoleId(), myImei, myDealPackage,
				he.getRoleId(), hisImei, hisDealPackage);
		me.addSmall_money(myAddSmallMoney);
		he.addSmall_money(hisAddSmallMoney);
	}

	// 更新技能列表
	@Transactional
	public void updateRoleSkills(String gsonSkills, int needSmallMoney,
			int roleId) {
		roleDao.updateRoleSkills(gsonSkills, needSmallMoney, roleId);
	}

	// 更新角色换线
	@Transactional
	public void updateRoleChangeLine(int line, int roleId) {
		roleDao.updateRoleChangeLine(line, roleId);
	}

	// 更新宠物列表
	@Transactional
	public void updateRolePets(String gsonPets, int roleId) {
		roleDao.updateRolePets(gsonPets, roleId);
	}

	// 初始化序列号
	public void initSerial() {
		serialDao.initSerial();
	}

	// 更新临时任务序列号
	@Transactional
	public void decreaseTempTaskSerial(int delta) {
		serialDao.decreaseTempTaskSerial(delta);
	}

	// 更新临时任务序列号
	@Transactional
	public void decreaseBossSerial(int delta) {
		serialDao.decreaseBossSerial(delta);
	}

	// 更新任务
	@Transactional
	public void updateRoleAfterTask(int i, int j, int k, int l, int m, int n,
			int o, int p, int q, int r, int s, int t, String string,
			String string2, String string3, int u, int v, String string4,
			int w, int x, int y, int z, int a, int b, int c) {
		roleDao.updateRoleAfterTask(i, j, k, l, m, n, o, p, q, r, s, t, string,
				string2, string3, u, v, string4, w, x, y, z, a, b, c);
	}

	// 打怪后，更新数据
	@Transactional
	public void batchUpdateSqlAfterBattle(List<Object[]> args) {
		roleDao.batchUpdateSqlAfterBattle(args);
	}

	// 角色加点:属性点，空白属性点
	@Transactional
	public void updateRolePoint(MmochatPlayer me) {
		roleDao.updateRolePoint(me);
	}

	// 角色加天赋:天赋点，空白天赋点
	@Transactional
	public void updateRoleGiftPoint(MmochatPlayer me) {
		roleDao.updateRoleGiftPoint(me);
	}

	// 吃药品后更新：更新药品集合,人当前气血，法力
	@Transactional
	public void updateRoleAfterEatDrug(String gsonPackage, int curBlood,
			int curSprit, String gsonPets, int roleId) {
		roleDao.updateRoleAfterEatDrug(gsonPackage, curBlood, curSprit,
				gsonPets, roleId);
	}

	// 更新好友列表
	@Transactional
	public void updateMyFriends(String gsonFriends, int roleId) {
		roleDao.updateMyFriends(gsonFriends, roleId);
	}

	// 更新黑名单列表
	@Transactional
	public void updateMyEnermys(String gsonEnermys, String gsonFriend,
			int roleId) {
		roleDao.updateMyEnermys(gsonEnermys, gsonFriend, roleId);
	}

	// 同时更新好友和黑名单
	@Transactional
	public void updateMyFriendsAndEnermys(String gsonEnermys,
			String gsonFriends, int roleId) {
		roleDao.updateMyFriendsAndEnermys(gsonEnermys, gsonFriends, roleId);
	}

	// 购买药品
	@Transactional
	public void buyDrug(String gsonPackage, int moneyNeed, int roleId) {
		roleDao.buyDrug(gsonPackage, moneyNeed, roleId);
	}

	// 购买物品
	@Transactional
	public void buySmallMoneyObj(String gsonPackage, int moneyNeed, int roleId) {
		roleDao.buySmallMoneyObj(gsonPackage, moneyNeed, roleId);
	}

	@Transactional
	public void buyBigMoneyObj(String gsonPackage, int moneyNeed,
			long limit_bigmoney, int roleId) {
		roleDao.buyBigMoneyObj(gsonPackage, moneyNeed, limit_bigmoney, roleId);
	}

	// 出售装备
	@Transactional
	public void sellEquip(String gsonPackage, int moneyAward, int roleId) {
		roleDao.sellEquip(gsonPackage, moneyAward, roleId);
	}

	// 更新钱庄游戏币
	@Transactional
	public void updateStoreMoney(int storedSmallMoney, int smallMoney,
			int roleId) {
		roleDao.updateStoreMoney(storedSmallMoney, smallMoney, roleId);
	}

	// 更新钱庄宠物
	@Transactional
	public void updateStorePet(String gsonStoredPets, int roleId) {
		roleDao.updateStorePet(gsonStoredPets, roleId);
	}

	// 获取前30名等级排行
	public List<MmochatRankPlayer> getTopLevelList() {
		return roleDao.getTopLevelList();
	}

	// 获取前30名道行排行
	public List<MmochatRankPlayer> getTopDaoList() {
		return roleDao.getTopDaoList();
	}

	// 获取前20名道行排行，一定等级内
	public List<MmochatRankPlayer> getTopDaoListByLevel(int minLevel,
			int maxLevel) {
		return roleDao.getTopDaoListByLevel(minLevel, maxLevel);
	}

	// 获取前30名战绩排行
	public List<MmochatRankPlayer> getTopZhanjiList() {
		return roleDao.getTopZhanjiList();
	}

	// 获取前30名金钱排行
	public List<MmochatRankPlayer> getTopSmallMoneyList() {
		return roleDao.getTopSmallMoneyList();
	}

	// 更新每日领药活动
	@Transactional
	public void updateFreeDrugActivity(String gsonPackage,
			String gsonDailyActivities, int roleId) {
		roleDao
				.updateFreeDrugActivity(gsonPackage, gsonDailyActivities,
						roleId);
	}

	// 更新道具效果
	@Transactional
	public void updateRoleAfterUseProp(String name, int level, int exp,
			int mapId, int x, int y, int curBlood, int curSprit,
			int bloodPoint, int attackPoint, int spritPoint, int speedPoint,
			int smallMoney, int bigMoney, int spacePoint, int dao, int zhanji,
			String gsonPackage, String gsonPets, String gsonPropEffects,
			int attack_gift_point, int sprit_gift_point, int blood_gift_point,
			int defend_gift_point, int speed_gift_point, int space_gift_point,
			String dailyActivities, String specialSkills, String lifeSkills,
			int roleId) {
		roleDao.updateRoleAfterUseProp(name, level, exp, mapId, x, y, curBlood,
				curSprit, bloodPoint, attackPoint, spritPoint, speedPoint,
				smallMoney, bigMoney, spacePoint, dao, zhanji, gsonPackage,
				gsonPets, gsonPropEffects, attack_gift_point, sprit_gift_point,
				blood_gift_point, defend_gift_point, speed_gift_point,
				space_gift_point, dailyActivities, specialSkills, lifeSkills,
				roleId);
	}

	// 改名
	@Transactional
	public void updateRoleName(String newName, String gsonPackage, int roleId) {
		roleDao.updateRoleName(newName, gsonPackage, roleId);
	}

	// 改造装备
	@Transactional
	public void modifyEquip(String gsonPackage, int smallMoneyNeed, int roleId) {
		roleDao.modifyEquip(gsonPackage, smallMoneyNeed, roleId);
	}

	// 更新玩家显示设置
	@Transactional
	public void updateRoleShowSet(int show_role_set_value, int roleId) {
		roleDao.updateRoleShowSet(show_role_set_value, roleId);
	}

	// 更新聊天频道设置
	@Transactional
	public void updateRoleChatSet(String show_chat_set, int roleId) {
		roleDao.updateRoleChatSet(show_chat_set, roleId);
	}

	// 更新玩家切磋设置
	@Transactional
	public void updateRoleFriendlyPk(boolean accept_friendlypk, int roleId) {
		roleDao.updateRoleFriendlyPk(accept_friendlypk, roleId);
	}

	// 更新玩家比武设置
	@Transactional
	public void updateRoleZhanjiPk(boolean accept_zhanjipk, int roleId) {
		roleDao.updateRoleZhanjiPk(accept_zhanjipk, roleId);
	}

	// 更新玩家其它设置
	@Transactional
	public void updateRoleOtherSetting(String setting, int roleId) {
		roleDao.updateRoleOtherSetting(setting, roleId);
	}

	// 更新角色死亡
	@Transactional
	public void updateRoleDead(int curBlood, int curSprit, String gsonPets,
			String gsonPackage, String gsonPropEffects, int mapId, int x,
			int y, int exp, int dao, int smallMoney, String activity, int roleId) {
		roleDao.updateRoleDead(curBlood, curSprit, gsonPets, gsonPackage,
				gsonPropEffects, mapId, x, y, exp, dao, smallMoney, activity,
				roleId);
	}

	// 更新玩家领取VIP双倍
	@Transactional
	public void updateRoleGetVipDouble(long lastGetVipDoublePropTime,
			String propEffect, int roleId) {
		roleDao.updateRoleGetVipDouble(lastGetVipDoublePropTime, propEffect,
				roleId);
	}

	// 创建帮派
	@Transactional
	public void createGang(String gSon_members, String name, MmochatPlayer me,
			Map<Integer, MmochatGang> gangs, String chenhao) {
		// 增加帮派
		gangDao.createGang(gSon_members, name);

		// 读取此帮派
		MmochatGang myGang = gangDao.getGangByName(name);

		// 将创建人的帮派ID设为此帮派
		roleDao.enjorGang(myGang.getId(), me.getRoleId());

		// 修改内存中创建人的帮派信息
		me.setGangId(myGang.getId());

		// 将此帮派加入内存中帮派集合里
		gangs.put(myGang.getId(), myGang);

		roleDao.updateRoleSmallMoneyAndChenhao(me.getRoleId(), (int) me
				.getSmall_money(), chenhao);
	}

	// 查找指定名字的帮派
	public MmochatGang getGangByName(String name) {
		return gangDao.getGangByName(name);
	}

	// 加入帮派
	@Transactional
	public void enjorGang(int gang_id, int roleId) {
		roleDao.enjorGang(gang_id, roleId);
	}

	// 查找指定ID的帮派
	public MmochatGang getGangById(int id) {
		return gangDao.getGangById(id);
	}

	public MmochatGang getGangByIdIncludeDeleted(int id) {
		return gangDao.getGangByIdIncludeDeleted(id);
	}

	// 创建战队
	@Transactional
	public void createPkTeam(String gSon_members, String name,
			MmochatPlayer me, Map<Integer, MmochatPkTeam> pkteams) {
		// 增加战队
		pkTeamDao.createPkTeam(gSon_members, name);

		// 读取此战队
		MmochatPkTeam myPkTeam = pkTeamDao.getPkTeamByName(name);

		// 将创建人的战队ID设为此战队
		roleDao.enjorPkTeam(myPkTeam.getId(), me.getRoleId());

		// 修改内存中创建人的战队信息
		me.setPkteam_id(myPkTeam.getId());

		// 将此战队加入内存中战队集合里
		pkteams.put(myPkTeam.getId(), myPkTeam);
	}

	// 查找指定ID的战队
	public MmochatPkTeam getPkTeamById(int id) {
		return pkTeamDao.getPkTeamById(id);
	}

	// 修改帮派公告
	@Transactional
	public void updateGangInfo(String newInfo, int id) {
		gangDao.updateGangInfo(newInfo, id);
	}

	// 踢除帮派成员
	@Transactional
	public void kickOutGangMember(String members, int gangId, int kickedRoleId,
			String tasks, String chenhao) {
		gangDao.updateGangMember(members, gangId);
		roleDao.enjorGang(-1, kickedRoleId);
		if (tasks != null) {
			roleDao.updateRoleTasksAndChenhao(tasks, chenhao, kickedRoleId);
		}
		MmochatPlayer me = MmochatMainService.getRoleFromBuffer(kickedRoleId);
		if (me != null) {
			me.setNoGang();
		}
	}

	// 更新帮派成员
	@Transactional
	public void updateGangMember(String members, int gangId) {
		gangDao.updateGangMember(members, gangId);
	}

	// 增加帮派成员
	@Transactional
	public void addGangMember(int roleId, String members, int gangId) {
		gangDao.updateGangMember(members, gangId);
		roleDao.enjorGang(gangId, roleId);
		MmochatPlayer me = MmochatMainService.getRoleFromBuffer(roleId);
		if (me != null) {
			me.setGangId(gangId);
		}
	}

	// 删除帮派
	@Transactional
	public void deleteGangById(int gangId, MmochatPlayer master) {
		gangDao.deleteGangById(gangId);
		roleDao.enjorGang(-1, master.getRoleId());
		master.setNoGang();
	}

	// 读取所有帮派
	public List<MmochatGang> getAllGang() {
		return gangDao.getAllGang();
	}

	// 完成帮派任务，更新帮派成员及帮派建设度
	@Transactional
	public void updateAfterGangTask(String members, int addBuildValue,
			int addmoney, int id) {
		gangDao.updateAfterGangTask(members, addBuildValue, addmoney, id);
	}

	// 重置帮派成员每周帮贡
	@Transactional
	public void resetGangMemberWeekBuildValue(String members, long time,
			int gangId) {
		gangDao.resetGangMemberWeekBuildValue(members, time, gangId);
	}

	// 研发帮派技能
	@Transactional
	public void developGangSkill(int buildUsed, String skills, int id) {
		gangDao.developGangSkill(buildUsed, skills, id);
	}

	// 成员学习帮派技能
	@Transactional
	public void learnGangSkill(String gangMembers, int gangId, String mySkills,
			int roleId) {
		gangDao.updateGangMember(gangMembers, gangId);
		roleDao.updateRoleGangSkill(mySkills, roleId);
	}

	// 更新帮派等级
	@Transactional
	public void updateGangLevel(int level, int id) {
		gangDao.updateGangLevel(level, id);
	}

	// 扣除帮派资金，加到帮主身上
	@Transactional
	public void delGangMoneyToManage(int delMoney, int gangId, int roleId) {
		gangDao.delGangMoney(delMoney, gangId);
		roleDao.addRoleSmallMoney(roleId, delMoney);
	}

	// 更新角色游戏币
	@Transactional
	public void updateRoleSmallMoney(int id, int money) {
		roleDao.updateRoleSmallMoney(id, money);
	}

	// 帮派大乱斗结束，更新帮派成员及帮派建设度，帮派资金
	@Transactional
	public void batchUpdateAfterGangPkGame(List<Object[]> args) {
		gangDao.batchUpdateAfterGangPkGame(args);
	}

	// 更新角色师徒信息
	@Transactional
	public void updateRoleTeacherAndStudent(int teacher_roleid,
			String teacher_name, String students, int roleId,
			int teacher_roleid2, String teacher_name2, String students2,
			int roleId2) {
		roleDao.updateRoleTeacherAndStudent(teacher_roleid, teacher_name,
				students, roleId);
		roleDao.updateRoleTeacherAndStudent(teacher_roleid2, teacher_name2,
				students2, roleId2);
	}

	// 更新角色师徒信息
	@Transactional
	public void updateRoleTeacherAndStudent(int teacher_roleid,
			String teacher_name, String students, int roleId) {
		roleDao.updateRoleTeacherAndStudent(teacher_roleid, teacher_name,
				students, roleId);
	}

	// 踢除徒弟
	@Transactional
	public void kickOutStudent(String students, MmochatPlayer teacher,
			int studentRoleId) {
		roleDao.updateRoleTeacherAndStudent(teacher.getTeacher_roleId(),
				teacher.getTeacher_name(), students, teacher.getRoleId());
		roleDao.updateRoleTeacher(-1, null, studentRoleId);
	}

	// 出师
	@Transactional
	public void gradute(String gsonPackage, int roleId) {
		roleDao.gradute(gsonPackage, roleId);
	}

	// 出师
	@Transactional
	public void gradute(int teacher_roleid, String teacher_name,
			String students, int roleId, String gsonPackage, int myRoleId) {
		roleDao.updateRoleTeacherAndStudent(teacher_roleid, teacher_name,
				students, roleId);
		roleDao.gradute(gsonPackage, myRoleId);
	}

	// 领取师傅工资
	@Transactional
	public void getTeacherSalary(String myPackage, int roleId) {
		roleDao.getTeacherSalary(myPackage, roleId);
	}

	// 更新玩家战绩
	@Transactional
	public void updateRoleZhanji(int zhanji, int roleId) {
		roleDao.updateRoleZhanji(zhanji, roleId);
	}

	// 更新同屏显示上限
	@Transactional
	public void updateScreenRoleNum(int screenRoleNum, int roleId) {
		roleDao.updateScreenRoleNum(screenRoleNum, roleId);
	}

	// 更新包裹
	@Transactional
	public void updateMyPackage(String gsonMyPackage, int smallMoney, int roleId) {
		roleDao.updateMyPackage(gsonMyPackage, smallMoney, roleId);
	}

	// 批量更新包裹
	@Transactional
	public void batchUpdateMyPackage(List<Object[]> args) {
		roleDao.batchUpdateMyPackage(args);
	}

	// 更新包裹和仓库
	@Transactional
	public void updateMyPackageAndStorage(String gsonMyPackage,
			String gsonMyStorage, int roleId) {
		roleDao.updateMyPackageAndStorage(gsonMyPackage, gsonMyStorage, roleId);
	}

	// 更新仓库
	@Transactional
	public void updateMyStorage(String gsonMyStorage, int roleId) {
		roleDao.updateMyStorage(gsonMyStorage, roleId);
	}

	// 通用数据库语句
	@Transactional
	public String commonSqlQuery(int tableKey, int actionType, String sql) {
		String ret = null;
		Gson gson = new Gson();
		int line;
		switch (tableKey) {
		case 0:
			switch (actionType) {
			case 0:
				line = gangDao.commonUpdate(sql);
				ret = "更新了" + line + "条记录。";
				break;
			case 1:
				List<MmochatGang> gangList = gangDao.commonQuery(sql);
				ret = gson.toJson(gangList, new TypeToken<List<MmochatGang>>() {
				}.getType());
				break;
			case 2:
				MmochatGang gang = gangDao.commonQueryForObject(sql);
				ret = gson.toJson(gang, new TypeToken<MmochatGang>() {
				}.getType());
				break;
			default:
				break;
			}
			break;
		case 1:
			switch (actionType) {
			case 0:
				line = pkTeamDao.commonUpdate(sql);
				ret = "更新了" + line + "条记录。";
				break;
			case 1:
				List<MmochatPkTeam> teamList = pkTeamDao.commonQuery(sql);
				ret = gson.toJson(teamList,
						new TypeToken<List<MmochatPkTeam>>() {
						}.getType());
				break;
			case 2:
				MmochatPkTeam team = pkTeamDao.commonQueryForObject(sql);
				ret = gson.toJson(team, new TypeToken<MmochatPkTeam>() {
				}.getType());
				break;
			default:
				break;
			}
			break;
		case 2:
			switch (actionType) {
			case 0:
				line = roleDao.commonUpdate(sql);
				ret = "更新了" + line + "条记录。";
				break;
			case 1:
				List<MmochatPlayer> playerList = roleDao.commonQuery(sql);
				ret = gson.toJson(playerList,
						new TypeToken<List<MmochatPlayer>>() {
						}.getType());
				break;
			case 2:
				MmochatPlayer player = roleDao.commonQueryForObject(sql);
				ret = gson.toJson(player, new TypeToken<MmochatPlayer>() {
				}.getType());
				break;
			default:
				break;
			}
			break;
		case 3:
			switch (actionType) {
			case 0:
				line = serialDao.commonUpdate(sql);
				ret = "更新了" + line + "条记录。";
				break;
			case 1:
				List<SerialClub> serialList = serialDao.commonQuery(sql);
				ret = gson.toJson(serialList,
						new TypeToken<List<SerialClub>>() {
						}.getType());
				break;
			case 2:
				SerialClub serial = serialDao.commonQueryForObject(sql);
				ret = gson.toJson(serial, new TypeToken<SerialClub>() {
				}.getType());
				break;
			default:
				break;
			}
			break;
		default:
			break;
		}
		return ret;
	}

	// 批量加金钱和元宝
	@Transactional
	public void batchUpdateMoney(List<Object[]> args) {
		roleDao.batchUpdateMoney(args);
	}

	// 更新日常活动和战绩
	@Transactional
	public void updateRoleDailyActivityAndZhanJi(int zhanJi, String Activity,
			int roleId) {
		roleDao.updateRoleDailyActivityAndZhanJi(zhanJi, Activity, roleId);
	}

	// 更新日常活动和包裹
	@Transactional
	public void updateRoleDailyActivityAndPackage(String myPackage,
			String Activity, int roleId) {
		roleDao.updateRoleDailyActivityAndPackage(myPackage, Activity, roleId);
	}

	// 更新日常活动和包裹和宠物
	@Transactional
	public void updateRoleDailyActivityAndPackageAndPet(String myPackage,
			String Activity, String pets, int roleId) {
		roleDao.updateRoleDailyActivityAndPackageAndPet(myPackage, Activity,
				pets, roleId);
	}

	// 更新日常活动
	@Transactional
	public void updateRoleDailyActivity(String Activity, int roleId) {
		roleDao.updateRoleDailyActivity(Activity, roleId);
	}

	// 更新奖券及连续天数,最后领取时间
	@Transactional
	public void updateRoleLottery(int lottery, int sustainedLotteryDays,
			long lastLotteryTime, int dao, int roleId) {
		roleDao.updateRoleLottery(lottery, sustainedLotteryDays,
				lastLotteryTime, dao, roleId);
	}

	// 更新奖券和包裹
	@Transactional
	public void updateRoleLotteryAndPackage(int lottery, String myPackage,
			int roleId) {
		roleDao.updateRoleLotteryAndPackage(lottery, myPackage, roleId);
	}

	// 批量更新玩家包裹和仓库
	@Transactional
	public void batchUpdatePackageAndStorage(List<Object[]> args) {
		roleDao.batchUpdatePackageAndStorage(args);
	}

	// 批量更新玩家道具效果
	@Transactional
	public void batchUpdateRolePropEffect(List<Object[]> args) {
		roleDao.batchUpdateRolePropEffect(args);
	}

	// 获取GM信息
	public MmochatGm getGmByName(String name) {
		return gmDao.getGmByName(name);
	}

	// 获取未处理的玩家问题
	public String getkefuQuestion() {
		List<String> questionList = kefuDao.getkefuQuestion();
		if (questionList == null || questionList.size() == 0) {
			return null;
		}
		return questionList.get(0);
	}

	// 更新未处理的玩家问题
	@Transactional
	public void saveKefuQuestion(String question) {
		kefuDao.saveKefuQuestion(question);
	}

	// 新增一条空记录
	@Transactional
	public void addNewKefuQuestion() {
		kefuDao.addNewKefuQuestion();
	}

	// 增加玩家道行
	@Transactional
	public void addRoleDao(int roleId, int add) {
		roleDao.addRoleDao(roleId, add);
	}

	// 增加玩家经验
	@Transactional
	public void addRoleExp(int roleId, int add) {
		roleDao.addRoleExp(roleId, add);
	}

	// 增加玩家战绩
	@Transactional
	public void addRoleZhanJi(int roleId, int add) {
		roleDao.addRoleZhanJi(roleId, add);
	}

	// 增加玩家金钱
	@Transactional
	public void addRoleSmallMoney(int roleId, int add) {
		roleDao.addRoleSmallMoney(roleId, add);
	}

	// 增加玩家元宝
	@Transactional
	public void addRoleBigMoney(int roleId, int add) {
		roleDao.addRoleBigMoney(roleId, add);
	}

	// 增加玩家奖券
	@Transactional
	public void addRoleLottery(int addLottery, int roleId) {
		roleDao.addRoleLottery(addLottery, roleId);
	}

	// 增加玩家等级和相应属性
	@Transactional
	public void addRoleLevelAndAttr(int level, int blood_point,
			int attack_point, int sprit_point, int speed_point,
			int space_point, int space_gift_point, int roleId) {
		roleDao
				.addRoleLevelAndAttr(level, blood_point, attack_point,
						sprit_point, speed_point, space_point,
						space_gift_point, roleId);
	}

	// 增加抽奖次数
	@Transactional
	public void addRoleAwardTimes(int roleId, int add) {
		roleDao.addRoleAwardTimes(roleId, add);
	}

	// 增加客服操作记录
	@Transactional
	public void addGmOptionLog(int kefu_id, int role_id, String role_name,
			int type, String content, String reason) {
		kefuOptionLogDao.addGmOptionLog(kefu_id, role_id, role_name, type,
				content, reason);
	}

	// 读取客服操作记录
	public List<MmochatKefuOptionLog> getGmOptionLogById(int type, int start,
			int count) {
		return kefuOptionLogDao.getGmOptionLogById(type, start, count);
	}

	// 获取name对应的roleId
	public int getRoleIdByName(String name) {
		return roleDao.getRoleIdByName(name);
	}

	// 更新所有序列号
	@Transactional
	public void updateSerial(int bossId, int taskId) {
		serialDao.updateSerial(bossId, taskId);
	}

	// 创建新订单
	@Transactional
	public void createNewOrder(long order_id, int roleid, long skyid,
			long create_time) {
		mmochatDirectPayDao
				.createNewOrder(order_id, roleid, skyid, create_time);
	}

	// 设置订单成功，并给玩家增加元宝
	@Transactional
	public boolean setOrderSuccess(String sky_chargeid, int rmb,
			String result_info, long order_id, int roleId, int addBigMoney,
			int addAwardTimes, long time, int dao, int exp) {
		int updateNum = mmochatDirectPayDao.setOrderSuccess(sky_chargeid, rmb,
				result_info, order_id, roleId);
		if (updateNum == 0) {
			// 没有记录被更新
			return false;
		}
		int pay = 0;
		if (MmochatConstant.isCalRoleTotalPay()) {
			pay = rmb;
		}
		roleDao.addRoleBigMoneyAndUpdatePayTime(roleId, addBigMoney,
				addAwardTimes, time, pay, dao, exp);
		return true;
	}

	// 设置订单失败
	@Transactional
	public int setOrderFailed(String sky_chargeid, int rmb, String result_info,
			long order_id, int roleId) {
		return mmochatDirectPayDao.setOrderFailed(sky_chargeid, rmb,
				result_info, order_id, roleId);
	}

	// 创建kb兑换新订单
	@Transactional
	public void createNewKbOrder(int roleid, long skyid, int kb, int bigmoney,
			int addAwardTimes, long time, int dao, int exp) {
		mmochatKbPayDao.createNewKbOrder(roleid, skyid, kb, bigmoney, time);
		int pay = 0;
		if (MmochatConstant.isCalRoleTotalPay()) {
			pay = kb;
		}
		roleDao.addRoleBigMoneyAndUpdatePayTime(roleid, bigmoney,
				addAwardTimes, time, pay, dao, exp);
	}

	// 预充值
	@Transactional
	public void delayPayOrder(int roleid, int bigmoney, int addAwardTimes,
			long time, int dao, int exp) {
		roleDao.addRoleBigMoneyAndUpdatePayTime(roleid, bigmoney,
				addAwardTimes, time, 0, dao, exp);
	}

	// 获取所有玩家等级信息(最近7天登陆过的)
	public List<MmochatRoleLevelInfoStatistics> getAllPlayerLevelInfo(long time) {
		return roleDao.getAllPlayerLevelInfo(time);
	}

	// 保存每日统计数据
	@Transactional
	public void saveDailyStatistics(long timeBefore7Day,
			Timestamp timeBefore6Day, int reg_num, int login_num,
			int loginNumOfYesterdayReg, int online_top,
			int online_time_average, int bigmoney_pay_role_num,
			int bigmoney_pay_total_money, String main_point_to_cost_smallmoney,
			String main_point_to_produce_smallmoney,
			String main_point_to_cost_bigmoney,
			String main_point_to_produce_bigmoney, String online_map,
			String direct_pay_role_money_map, String kb_pay_role_money_map,
			int suggest_reg_num, long today_score_to_bigmoney_count,
			long today_score_to_kb_count, String levelInfo,
			String activityLevelInfo, int todayDirectPayTimes,
			int todayKBPayTimes, String today_propCostPointMap) {
		// 累计总注册用户数
		int total_reg_num = roleDao.getTotalRoleNum();
		// 获取元宝剩余总量
		long total_bigmoney_rest = roleDao.getTotalBigMoney();
		// 元宝订单中的元宝
		for (MmochatBigMoneyDeal deal : MmochatBigMoneyDealService.dealMap
				.values()) {
			if (deal.getType() == MmochatBigMoneyDealType.寄售) {
				total_bigmoney_rest += deal.getRest();
			}
		}
		// 获取游戏币剩余总量
		long total_smallmoney_rest = roleDao.getTotalSmallMoney();
		total_smallmoney_rest += mmochatShopDao.getTotalSmallMoney();
		// 元宝订单中的金钱
		for (MmochatBigMoneyDeal deal : MmochatBigMoneyDealService.dealMap
				.values()) {
			if (deal.getType() == MmochatBigMoneyDealType.求购) {
				total_smallmoney_rest += deal.getRest() * deal.getPrice() * 100;
			}
		}

		// 获取7天内登陆过的用户数
		int login_in_seven_day_role_num = roleDao.getLoginNumIn7Day(
				timeBefore7Day, timeBefore6Day);

		mmochatStatisticsDao.saveDailyStatistics(reg_num, login_num,
				loginNumOfYesterdayReg, online_top, online_time_average,
				bigmoney_pay_role_num, bigmoney_pay_total_money, total_reg_num,
				login_in_seven_day_role_num, total_smallmoney_rest,
				main_point_to_cost_smallmoney,
				main_point_to_produce_smallmoney, main_point_to_cost_bigmoney,
				main_point_to_produce_bigmoney, online_map,
				direct_pay_role_money_map, kb_pay_role_money_map,
				total_bigmoney_rest, suggest_reg_num,
				today_score_to_bigmoney_count, today_score_to_kb_count,
				levelInfo, activityLevelInfo, todayDirectPayTimes,
				todayKBPayTimes, today_propCostPointMap);
	}

	// 保存每月统计数据
	@Transactional
	public void saveMonthlyStatistics(long lastMonthTime,
			Timestamp twoMonthBefore) {
		int activity_role_num = roleDao.getMonthlyActivityRoleNum();
		int cur_month_login_num = roleDao.getMonthlyLoginRoleNum(lastMonthTime);
		int cur_month_pay_role_num = roleDao
				.getMonthlyPayRoleNum(lastMonthTime);
		int cur_month_direct_pay_total_money = -1;
		try {
			cur_month_direct_pay_total_money = mmochatDirectPayDao
					.getMonthlyDirectPayTotalValue(lastMonthTime);
		} catch (EmptyResultDataAccessException e) {
		}
		int cur_month_kb_pay_total_money = -1;
		try {
			cur_month_kb_pay_total_money = mmochatKbPayDao
					.getMonthlyKBPayTotalValue(lastMonthTime);
		} catch (EmptyResultDataAccessException e) {
		}
		int cur_month_pay_total_money = cur_month_direct_pay_total_money
				+ cur_month_kb_pay_total_money;

		mmochatStatisticsDao.saveMonthlyStatistics(activity_role_num,
				cur_month_login_num, cur_month_pay_role_num,
				cur_month_pay_total_money);

		// 删除2个月前的deal_log和bigmoneydeallog
		try {
			mmochatDealLogDao.delDealLogByTime(twoMonthBefore);
			mmochatBigMoneyDealDao.delBigMoneyDealOrderByTime(twoMonthBefore
					.getTime());
		} catch (Exception e) {
			// 如果删除操作失败，则不回滚
			e.printStackTrace();
		}
	}

	// 查询用户日报表数据
	public List<MmochatDailyUserStatistics> queryDailyUserStatistics(
			Timestamp startDate, Timestamp endDate) {
		return mmochatStatisticsDao
				.queryDailyUserStatistics(startDate, endDate);
	}

	// 查询消费日报表数据
	public List<MmochatDailyMoneyStatistics> queryDailyMoneyStatistics(
			Timestamp startDate, Timestamp endDate) {
		return mmochatStatisticsDao.queryDailyMoneyStatistics(startDate,
				endDate);
	}

	// 查询月报表数据
	public List<MmochatMonthlyStatistics> queryMonthlyStatistics(
			Timestamp startDate, Timestamp endDate) {
		return mmochatStatisticsDao.queryMonthlyStatistics(startDate, endDate);
	}

	// 查询指定玩家的交易记录
	public List<MmochatDealLog> queryRoleDealLog(int roleId,
			Timestamp startDate, Timestamp endDate) {
		return mmochatDealLogDao.queryRoleDealLog(roleId, startDate, endDate);
	}

	// 获取指定name的角色，包括已删除角色
	public MmochatPlayer getRoleByName(String name) {
		return roleDao.getRoleByName(name);
	}

	// 更新积分和元宝
	@Transactional
	public void updateSuggestScoreAndBigmoney(int delSuggestScore,
			int addBigMoney, int roleId) {
		roleDao.updateSuggestScoreAndBigmoney(delSuggestScore, addBigMoney,
				roleId);
	}

	// 给推荐人增加积分
	@Transactional
	public int addSuggestScore(int addScore, int roleId) {
		return roleDao.addSuggestScore(addScore, roleId);
	}

	// 更新包裹、宠物、游戏币、道行和抽奖次数
	@Transactional
	public void updateRoleAfterAward(String myPackage, String pets,
			int addSuggestScore, int smallMoney, int dao, int rest_award_times,
			int roleId) {
		roleDao.updateRoleAfterAward(myPackage, pets, addSuggestScore,
				smallMoney, dao, rest_award_times, roleId);
	}

	// 更新宠物列表和宠物仓库
	@Transactional
	public void updateRolePetsAfterStore(String gsonPets,
			String gsonStoredPets, int roleId) {
		roleDao.updateRolePetsAfterStore(gsonPets, gsonStoredPets, roleId);
	}

	// 查询指定交易记录
	public MmochatDealLog queryRoleDealLogById(int id) {
		return mmochatDealLogDao.queryRoleDealLogById(id);
	}

	// 读取所有未结束的交易
	public List<MmochatBigMoneyDeal> getAllUnclosedDeal() {
		return mmochatBigMoneyDealDao.getAllUnclosedDeal();
	}

	// 创建新订单
	@Transactional
	public void createBigMoneyDealOrder(MmochatBigMoneyDeal newOrder,
			int addSmallMoney, int addBigMoney) throws Exception {
		int id = mmochatBigMoneyDealDao.createNewOrderId();
		newOrder.setId(id);
		mmochatBigMoneyDealDao.createNewOrder(newOrder);
		if (addSmallMoney != 0) {
			roleDao.addRoleSmallMoney(newOrder.getRoleId(), addSmallMoney);
		}
		if (addBigMoney != 0) {
			roleDao.addRoleBigMoney(newOrder.getRoleId(), addBigMoney);
		}
	}

	// 购买元宝订单
	@Transactional
	public void buyBigMoneyDeal(int del, int state, String dealmap, int id,

	int buyer_bigMoneyAdd, int buyer_smallMoneyAdd,
			int buyer_account_bigMoneyAdd, int buyer_account_smallMoneyAdd,
			long buyer_limit_bigMoney, int buyer_roleId,

			int seller_bigMoneyAdd, int seller_smallMoneyAdd,
			int seller_account_bigMoneyAdd, int seller_account_smallMoneyAdd,
			long seller_limit_bigMoney, int seller_roleId) {
		// 更新订单
		mmochatBigMoneyDealDao.updateOrder(del, state, dealmap, id);

		// 更新玩家信息
		roleDao
				.updateRoleAfterBigMoneyDeal(buyer_bigMoneyAdd,
						buyer_smallMoneyAdd, buyer_account_bigMoneyAdd,
						buyer_account_smallMoneyAdd, buyer_limit_bigMoney,
						buyer_roleId);
		roleDao.updateRoleAfterBigMoneyDeal(seller_bigMoneyAdd,
				seller_smallMoneyAdd, seller_account_bigMoneyAdd,
				seller_account_smallMoneyAdd, seller_limit_bigMoney,
				seller_roleId);
	}

	// 批量设置元宝过期，并归还玩家金钱元宝
	@Transactional
	public void batchUpdateAfterBigMoneyDealTimeOut(List<Object[]> orderArgs,
			List<Object[]> playerArgs) {
		mmochatBigMoneyDealDao.batchUpdateOrderState(orderArgs);
		roleDao.batchUpdateRoleAfterBigMoneyDealTimeOut(playerArgs);
	}

	// 批量设置元宝过期，并归还玩家金钱元宝
	@Transactional
	public void batchDeleteBigMoneyDeal(List<Object[]> orderArgs) {
		mmochatBigMoneyDealDao.batchUpdateOrderState(orderArgs);
	}

	// 从交易账户取出元宝
	@Transactional
	public void getBigMoneyFromDealAccount(int getValue, int roleId) {
		roleDao.getBigMoneyFromDealAccount(getValue, roleId);
	}

	// 从交易账户取出金钱
	@Transactional
	public void getSmallMoneyFromDealAccount(int getValue, int roleId) {
		roleDao.getSmallMoneyFromDealAccount(getValue, roleId);
	}

	// 查询最近几个游戏币相关的记录
	public List<MmochatSmallMoneyStatistics> queryLatestSmallMoneyStatistics(
			Timestamp startDate, Timestamp endDate) {
		return mmochatStatisticsDao.queryLatestSmallMoneyStatistics(startDate,
				endDate);
	}

	// 查询最近几个元宝相关的记录
	public List<MmochatBigMoneyStatistics> queryLatestBigMoneyStatistics(
			Timestamp startDate, Timestamp endDate) {
		return mmochatStatisticsDao.queryLatestBigMoneyStatistics(startDate,
				endDate);
	}

	// 创建GM
	@Transactional
	public void addGm(MmochatGm gm) {
		int id = gmDao.createNewGmId();
		gm.setId(id);
		gmDao.addGm(id, gm.getUsername(), gm.getPassword(), gm.getPriority(),
				gm.getTruename());
	}

	// 获取所有GM
	public List<MmochatGm> getAllGm() {
		return gmDao.getAllGm();
	}

	// 删除GM
	@Transactional
	public void delGm(String username) {
		gmDao.delGm(username);
	}

	// 修改GM信息
	@Transactional
	public void editGm(String truename, int priority, String username) {
		gmDao.editGm(truename, priority, username);
	}

	// 修改GM信息
	@Transactional
	public void editGmPwd(String pwd, String username) {
		gmDao.editGmPwd(pwd, username);
	}

	// 查询在线分布
	public String queryOnlineMap(Timestamp startDate, Timestamp endDate) {
		return mmochatStatisticsDao.queryOnlineMap(startDate, endDate);
	}

	// 查询等级分布
	public MmochatRoleLevelInfo queryLevelMap(Timestamp startDate,
			Timestamp endDate) {
		List<MmochatRoleLevelInfo> levelInfoList = mmochatStatisticsDao
				.queryLevelMap(startDate, endDate);
		if (levelInfoList == null || levelInfoList.size() == 0) {
			return null;
		}
		return levelInfoList.get(0);
	}

	// 结婚,role1出钱
	@Transactional
	public void marry(MmochatPlayer role1, MmochatPlayer role2, int delMoney) {
		roleDao.marry(role2.getRoleId(), role2.getName(), delMoney, role1
				.getRoleId());
		roleDao.marry(role1.getRoleId(), role1.getName(), 0, role2.getRoleId());
	}

	// 离婚
	@Transactional
	public void unMarry(MmochatPlayer role1, MmochatPlayer role2) {
		if (role1 != null) {
			roleDao.marry(-1, null, 0, role1.getRoleId());
		}
		if (role2 != null) {
			roleDao.marry(-1, null, 0, role2.getRoleId());
		}
	}

	// 增加新的活动记录
	@Transactional
	public void addNewActivityRecord(long skyId, int roleId, int count,
			int type, String text) {
		mmochatActivityRecordDao.addNewActivityRecord(skyId, roleId, count,
				type, text);
	}

	// 查询活动记录
	public List<MmochatActivityRecord> getActivityRecord(int type) {
		return mmochatActivityRecordDao.getActivityRecord(type);
	}

	// 查询活动记录
	public List<MmochatActivityRecord> getActivityRecord2(int type,
			Timestamp startDate, Timestamp endDate) {
		return mmochatActivityRecordDao.getActivityRecord2(type, startDate,
				endDate);
	}

	// 读取所有商店
	public List<MmochatPlayerShop> getAllShops(int startId, int endId) {
		return mmochatShopDao.getAllShops(startId, endId);
	}

	// 创建新商店
	@Transactional
	public void createNewShop(MmochatPlayerShop shop, String grids,
			int moneyCost, int roleId) {
		int id = mmochatShopDao.createNewShopId();
		mmochatShopDao.createNewShop(id, shop.getRoleId(), shop.getName(), shop
				.getShopType().getKey(), grids, shop.getState().getKey(), shop
				.getRoleName(), shop.getShopMoney());
		roleDao.addRoleSmallMoney(roleId, -1 * moneyCost);
		shop.setId(id);
	}

	// 获取新的商店ID
	public int createNewShopId() {
		return mmochatShopDao.createNewShopId();
	}

	// 商店上架
	@Transactional
	public void addObjToShop(String myPackage, int roleId, String shopGrids,
			int pageNum, int shopId) {
		roleDao.updatePackageOnly(myPackage, roleId);
		mmochatShopDao.updateShop(shopGrids, pageNum, shopId);
	}

	// 宠物上架
	@Transactional
	public void addPetToShop(String pet, int roleId, String shopGrids,
			int pageNum, int shopId) {
		roleDao.updateRolePets(pet, roleId);
		mmochatShopDao.updateShop(shopGrids, pageNum, shopId);
	}

	// 物品下架
	@Transactional
	public void getObjFromShop(String pet, String pack, int roleId,
			String shopGrids, int pageNum, int shopId) {
		roleDao.updateRolePetAndPackage(pet, pack, roleId);
		mmochatShopDao.updateShop(shopGrids, pageNum, shopId);
	}

	// 更新好友列表和元宝
	@Transactional
	public void updateMyFriendsAndDelBigMoney(String gsonFriends,
			int delBigMoney, long limit_bigmoney, int roleId,
			String gsonFriends2, int roleId2) {
		roleDao.updateMyFriendsAndDelBigMoney(gsonFriends, delBigMoney,
				limit_bigmoney, roleId);
		roleDao.updateMyFriends(gsonFriends2, roleId2);
	}

	// 获取前N名充值排名
	public List<MmochatRolePayInfo> getTopPayList(int topCount) {
		return roleDao.getTopPayList(topCount);
	}

	// 地图守护神
	@Transactional
	public void saveMapGuiderData(int addDao, String pets,
			String daily_activities, int zhanJi, int roleId) {
		roleDao.saveMapGuiderData(addDao, pets, daily_activities, zhanJi,
				roleId);
	}

	// 增加商店金钱
	@Transactional
	public void addShopMoney(int roleId, int add, int id) {
		mmochatShopDao.addShopMoney(add, id);
		roleDao.addRoleSmallMoney(roleId, -1 * add);
	}

	// 修改商店状态
	@Transactional
	public void editShopState(int state, int id) {
		mmochatShopDao.editShopState(state, id);
	}

	// 修改商店公告
	@Transactional
	public void editShopIntro(String intro, int id) {
		mmochatShopDao.editShopIntro(intro, id);
	}

	// 增加商店柜台
	@Transactional
	public void addShopPage(int roleId, int costMoney, String shopGrids,
			int pageNum, int shopId) {
		mmochatShopDao.updateShop(shopGrids, pageNum, shopId);
		roleDao.addRoleSmallMoney(roleId, -1 * costMoney);
	}

	// 更新商店柜台数据
	@Transactional
	public void updateShopPage(String shopGrids, int pageNum, int shopId) {
		mmochatShopDao.updateShop(shopGrids, pageNum, shopId);
	}

	// 出售商店/取消出售
	@Transactional
	public void sellShop(int state, int price, int id) {
		mmochatShopDao.sellShop(state, price, id);
	}

	// 更改商店所有人
	@Transactional
	public void buyShop(int roleid, int state, String role_name, int shopId,
			int costMoney, int sellerRoleId) {
		mmochatShopDao.updateShopOwner(roleid, state, role_name, shopId);
		roleDao.addRoleSmallMoney(roleid, -1 * costMoney);
		roleDao.addRoleSmallMoney(sellerRoleId, costMoney);
	}

	// 购买商店物品
	@Transactional
	public void buyShopObj(String grids, int payMoney, int shopEarnMoney,
			String sellLog, int winScore, int shopId, String myPackage,
			int roleId) {
		mmochatShopDao.updateShopGridAndMoney(grids, shopEarnMoney, sellLog,
				winScore, shopId);
		roleDao.buySmallMoneyObj(myPackage, payMoney, roleId);
	}

	// 购买商店宠物
	@Transactional
	public void buyShopPet(String grids, int payMoney, int shopEarnMoney,
			String sellLog, int winScore, int shopId, String pet, int roleId) {
		mmochatShopDao.updateShopGridAndMoney(grids, shopEarnMoney, sellLog,
				winScore, shopId);
		roleDao.buyPet(pet, payMoney, roleId);
	}

	// 商店扣租金
	@Transactional
	public void updateShopDailyPay(int del, int state, int delScore, int id) {
		mmochatShopDao.updateShopDailyPay(del, state, delScore, id);
	}

	// 保存称号
	@Transactional
	public void saveChenhao(String chenhao, int id) {
		roleDao.saveChenhao(chenhao, id);
	}

	// 增加道行并更新称号
	@Transactional
	public void addRoleDaoAndUpdateChenhao(String chenhao, int add, int roleId) {
		roleDao.addRoleDaoAndUpdateChenhao(chenhao, add, roleId);
	}

	// 更新包裹、元宝、道行
	@Transactional
	public void updateRolePackage_BigMoney_Dao(String pack, int addDao,
			int addBigMoney, int roleId) {
		roleDao.updateRolePackage_BigMoney_Dao(pack, addDao, addBigMoney,
				roleId);
	}

	// 查询指定玩家的KB充值额
	public int getKBPayById(int roleId) {
		return mmochatKbPayDao.getKBPayById(roleId);
	}

	// 查询指定玩家在指定时间内的KB充值额
	public int getKBPayByIdAndTime(int roleId, long startTime, long endTime) {
		return mmochatKbPayDao.getKBPayByIdAndTime(roleId, startTime, endTime);
	}

	// 查询指定玩家的卡密充值额
	public int getDirectPayById(int roleId) {
		return mmochatDirectPayDao.getDirectPayById(roleId);
	}

	// 查询指定玩家的指定时间的充值额
	public int getDirectPayByIdAndTime(int roleId, long startTime, long endTime) {
		return mmochatDirectPayDao.getDirectPayByIdAndTime(roleId, startTime,
				endTime);
	}

	// 增加事件记录
	@Transactional
	public void addEventLog(int type, long time, String title, String content) {
		mmochatEventDao.addEventLog(type, time, title, content);
	}

	// 读取事件记录
	public List<MmochatEventLog> getEventLog(int type, long startTime,
			long endTime) {
		return mmochatEventDao.getEventLog(type, startTime, endTime);
	}

	// 读取所有事件记录
	public List<MmochatEventLog> getAllEventLog(long startTime) {
		return mmochatEventDao.getAllEventLog(startTime);
	}

	// 转生
	@Transactional
	public void reborn(MmochatPlayer me) {
		roleDao.reborn(me);
	}

	// 仙魔转换
	@Transactional
	public void changSecondRoleType(MmochatSecondRoleType roleType,
			int costBigMoney, long limit_bigmoney, int roleId) {
		roleDao.changSecondRoleType(roleType, costBigMoney, limit_bigmoney,
				roleId);
	}

	// 封号到一定时间
	@Transactional
	public void forbiddenRole(long tick, int roleId) {
		roleDao.forbiddenRole(tick, roleId);
	}

	// 保存经验、道行
	@Transactional
	public void saveExpAndDao(int exp, int dao, int roleId) {
		roleDao.saveExpAndDao(exp, dao, roleId);
	}

	// 保存包裹、道行、战绩、游戏币
	@Transactional
	public void savePackageDaoZhanJiSmallMoney(String gsonPackage, int dao,
			int zhanJi, int addSmallMoney, int roleId) {
		roleDao.savePackageDaoZhanJiSmallMoney(gsonPackage, dao, zhanJi,
				addSmallMoney, roleId);
	}

	// 增加声望
	@Transactional
	public void setHonor(long honor, int roleId) {
		roleDao.setHonor(honor, roleId);
	}

	@Transactional
	public void saveHonorExpDao(long honor, int exp, int dao, int roleId) {
		roleDao.saveHonorExpDao(honor, exp, dao, roleId);
	}

	@Transactional
	public void saveHonorAndPackage(long honor, String pack, int roleId) {
		roleDao.saveHonorAndPackage(honor, pack, roleId);
	}

	@Transactional
	public void saveHonorAndPets(long honor, String pet, int roleId) {
		roleDao.saveHonorAndPets(honor, pet, roleId);
	}

	@Transactional
	public void saveHonorAndSmallMoney(long honor, int delSmallMoney, int roleId) {
		roleDao.saveHonorAndSmallMoney(honor, delSmallMoney, roleId);
	}

	// 创建钱庄密码
	@Transactional
	public void createStorePwd(String pwd, int state,
			long release_store_pwd_time, int roleId) {
		roleDao.createStorePwd(pwd, state, release_store_pwd_time, roleId);
	}

	// 读取role表总记录数
	public int getRoleNum() {
		return roleDao.getRoleNum();
	}

	public List<MergeStep2Model1> getMergeStep2Model1(int start, int end) {
		return roleDao.getMergeStep2Model1(start, end);
	}

	@Transactional
	public void updateMergeStep2Model1(List<Object[]> args) {
		roleDao.updateMergeStep2Model1(args);
	}

	@Transactional
	public void updateExtraAndPackage(long extra, String packageStr, int id) {
		roleDao.updateExtraAndPackage(extra, packageStr, id);
	}

	// 读取gang表总记录数
	public int getGangNum() {
		return gangDao.getGangNum();
	}

	// 合服时读取所有帮派
	public List<MmochatGang> getAllGangOfMergeServer() {
		return gangDao.getAllGangOfMergeServer();
	}

	// 更新合服帮派成员
	@Transactional
	public void updateGangMemberOfMergeServer(String members, int gangId) {
		gangDao.updateGangMemberOfMergeServer(members, gangId);
	}

	// public List<TestModel> test(int s, int e) {
	// return roleDao.test(s, e);
	// }

	// 更新副本完成奖励
	@Transactional
	public void updateRoleAfterFuBen(String daily_activities,
			String gsonPackage, int exp, int level, int dao, int fubenid,
			String pets, int small_money, int roleId) {
		roleDao.updateRoleAfterFuBen(daily_activities, gsonPackage, exp, level,
				dao, fubenid, pets, small_money, roleId);
	}

	// 更新秘籍技能
	@Transactional
	public void updateRoleSpecialSkill(String special_skills, int roleId) {
		roleDao.updateRoleSpecialSkill(special_skills, roleId);
	}

	// 训练技能熟练度
	@Transactional
	public void trainRoleSpecialSkill(int big_money, String special_skills,
			String daily_activities, int roleId) {
		roleDao.trainRoleSpecialSkill(big_money, special_skills,
				daily_activities, roleId);
	}

	// 更新副本ID和每日活动
	@Transactional
	public void updateGangFuBenInfo(String activity, int gangId) {
		gangDao.updateGangFuBenInfo(activity, gangId);
	}

	// 更新帮派建设度和帮派资金
	@Transactional
	public void updateGangBuildAndMoney(int addBuildValue, int money, int id) {
		gangDao.updateGangBuildAndMoney(addBuildValue, money, id);
	}

	// 使用道具后，变更门派
	@Transactional
	public void changeFamily(String skills, int family, int roleType,
			String gsonPackage, int roleId) {
		roleDao.changeFamily(skills, family, roleType, gsonPackage, roleId);
	}

	// 变更性别
	@Transactional
	public void changeSex(int sex, int type, int bmpId, int roleId) {
		roleDao.changeSex(sex, type, bmpId, roleId);
	}

	// 读取竞技点
	public Integer getPkScore(int roleId) {
		return roleDao.getPkScore(roleId);
	}

	// 更新竞技点
	@Transactional
	public void updatePkScore(int score, int roleId) {
		roleDao.updatePkScore(score, roleId);
	}

	// 更新生活技能
	@Transactional
	public void updateLifeSkill(String life_skills, int roleId) {
		roleDao.updateLifeSkill(life_skills, roleId);
	}

	// 更新生活技能和宠物列表
	@Transactional
	public void updateLifeSkillAndPets(String gsonPets, String life_skills,
			String dailyActivity, int roleId) {
		roleDao.updateLifeSkillAndPets(gsonPets, life_skills, dailyActivity,
				roleId);
	}

	// 保存心情
	@Transactional
	public void updateMood(String mood, int roleId) {
		roleDao.updateMood(mood, roleId);
	}

	// 更新包裹、元宝、道行、经验、战绩
	@Transactional
	public void updateRoleOnlineAward(String pack, int addDao, int addBigMoney,
			int addExp, int addZhangji, int roleId) {
		roleDao.updateRoleOnlineAward(pack, addDao, addBigMoney, addExp,
				addZhangji, roleId);
	}

	// 按IMEI获取前N个用户
	public List<MmochatRolePayInfo> getRoleByImei(String imei, int limitNum) {
		return roleDao.getRoleByImei(imei, limitNum);
	}

	// 更新玩家诚信信息
	@Transactional
	public void setChiefRecord(String mood, String setting, int roleId) {
		roleDao.setChiefRecord(mood, setting, roleId);
	}

	// 更新宠物列表和宠物仓库
	@Transactional
	public void getBorrowedPetBack(String gsonPets, String gsonStoredPets,
			int roleId, String gsonStoredPets2, int roleId2) {
		roleDao.updateRolePetsAfterStore(gsonPets, gsonStoredPets, roleId);
		roleDao.updateStorePet(gsonStoredPets2, roleId2);
	}

	// 更新包裹和仓库
	@Transactional
	public void getBorrowedObjBack(String gsonMyPackage, int smallMoney,
			int roleId, String gsonMyPackage2, String gsonMyStorage2,
			int roleId2) {
		roleDao.updateMyPackage(gsonMyPackage, smallMoney, roleId);
		roleDao.updateMyPackageAndStorage(gsonMyPackage2, gsonMyStorage2,
				roleId2);
	}

	// 更新SkyId
	@Transactional
	public void updateRoleSkyId(long newSkyId, int roleId) {
		roleDao.updateRoleSkyId(newSkyId, roleId);
	}

	// 读取交易记录最大值
	public int getDelDealLogMaxId() {
		return mmochatDealLogDao.getDelDealLogMaxId();
	}

	// 读取交易记录最小值
	public int getDelDealLogMinId(Timestamp startDate) {
		return mmochatDealLogDao.getDelDealLogMinId(startDate);
	}

	// 读取有借条的roleId1
	public List<Integer> queryBorrowedRole1DealLog(int s, int e) {
		return mmochatDealLogDao.queryBorrowedRole1DealLog(s, e);
	}

	// 读取有借条的roleId2
	public List<Integer> queryBorrowedRole2DealLog(int s, int e) {
		return mmochatDealLogDao.queryBorrowedRole2DealLog(s, e);
	}

	// 获取包裹、仓库、宠物，仓库宠物
	public MergeStep1Model1 getMergeStep1Model1(int roleId) {
		return roleDao.getMergeStep1Model1(roleId);
	}

	// 更新包裹、仓库、宠物，仓库宠物
	@Transactional
	public void updateMergeStep1Model1(String packageStr, String storage,
			String pets, String stored_pets, int roleId) {
		roleDao.updateMergeStep1Model1(packageStr, storage, pets, stored_pets,
				roleId);
	}

	// 获取包裹、仓库、仓库宠物
	public MergeStep1Model4 getMergeStep1Model4(int roleId) {
		return roleDao.getMergeStep1Model4(roleId);
	}

	// 更新包裹、仓库、仓库宠物
	@Transactional
	public void updateMergeStep1Model4(String packageStr, String storage,
			String stored_pets, int roleId) {
		roleDao
				.updateMergeStep1Model4(packageStr, storage, stored_pets,
						roleId);
	}

}
